﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for DaiLyDAL
/// </summary>
public class DaiLyDAL
{
	public DaiLyDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable fnG_GetDataDaiLy()
    {
        string strSQL = "select * from DaiLy";
        return DataProvider.GetData(strSQL);
    }

    public DaiLyEntity fnG_GetDaiLy(string madl)
    {
        string strSQL = "select * from DaiLy WHERE iddl=@iddl";
        DataTable table= DataProvider.GetData(strSQL,"@iddl",madl);
        if(table.Rows.Count>0)
        {
            DaiLyEntity daily = new DaiLyEntity();
            daily.Iddl = Int32.Parse(table.Rows[0]["Iddl"].ToString());
            daily.DiaChi = table.Rows[0]["DiaChi"].ToString();
            daily.DienThoai = table.Rows[0]["DienThoai"].ToString();
            daily.Email = table.Rows[0]["Email"].ToString();
            daily.Fax = table.Rows[0]["Fax"].ToString();
            daily.Logo = table.Rows[0]["Logo"].ToString();
            daily.Mota = table.Rows[0]["Mota"].ToString();
            daily.TenDaiLy = table.Rows[0]["TenDaiLy"].ToString();
            return daily;
        }
        return null;
    }

    public void fn_AddDaiLy(DaiLyEntity daily)
    {
        string strSQL = "insert into DaiLy([TenDaiLy],[Logo],[DiaChi],[DienThoai],[Fax],[Email],[Mota]) "+
            " values (@TenDaiLy,@Logo,@DiaChi,@DienThoai,@Fax,@Email,@Mota)";
        DataProvider.ExecuteNonQuery(strSQL, "@TenDaiLy",daily.TenDaiLy,"@Logo",daily.Logo,"@DiaChi"
            ,daily.DiaChi,"@DienThoai",daily.DienThoai,"@Fax",daily.Fax,"@Email",daily.Email,"@Mota",daily.Mota);
        
    }

    public void fn_DelDaiLy(string p)
    {
        string sql = "Delete DaiLy Where iddl=@iddl ";
        DataProvider.ExecuteNonQuery(sql, "@iddl", p);
    }

    public void fn_UpdateDaiLy(DaiLyEntity daily)
    {
        string strSQL = "UPDATE DaiLy SET [TenDaiLy]=@TenDaiLy,[Logo]=@Logo,[DiaChi]=@DiaChi,[DienThoai]=@DienThoai,[Fax]=@Fax,[Email]=@Email,[Mota]=@Mota WHERE iddl=@iddl";
        DataProvider.ExecuteNonQuery(strSQL, "@TenDaiLy", daily.TenDaiLy, "@Logo", daily.Logo, "@DiaChi"
            , daily.DiaChi, "@DienThoai", daily.DienThoai, "@Fax", daily.Fax, "@Email", daily.Email, "@Mota", daily.Mota,"@iddl",daily.Iddl);
    }
}
